<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>index</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../../../css/mui.min.css">
		<meta name="referrer" content="never" />
		<link rel="stylesheet" href="../work.css" />
		<link rel="stylesheet" href="../../static/css/common.css">
		<link rel="stylesheet" href="../../static/components/components.css" />
		<style>
			*{
				/* touch-action: none;，，，，，，，，，，，，，，， */
			}
			html,
			body {
				background-color: #efeff4;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav mui-bar-nav-bg">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">直流系统</h1>
		</header>
		<div class="mui-content" id="content">
			<div class="main_box">
				<div class="main_icon"></div>
				<div class="main_icon1"></div>
				<div class="box_title">
					<div class="icon"></div>
					<div style="font-size: 4vw;">基础信息</div>
				</div>
				<!-- <div class="procee_line">
					<span>领取任务</span>
					<img src="../../../../img/post.png" class="icon_circle" />
					<div class="line"></div>
					<span>录入信息</span>
					<img src="../../../../img/post.png" class="icon_circle" />
					<div class="line"></div>
					<span>确认信息</span>
					<img src="../../../../img/post.png" class="icon_circle" v-if="status>30"/>
					<img src="../../../../img/wait.png" class="icon_circle" v-else />
				</div> -->
				<div class="flex_row mt-10">
					<div class="form_label">批准人</div>
					<personselect :disabled="workStatus ==30" :issingle="isSingle" ref="personselect_approve" style="width:55vw;"></personselect>
				</div>
				<div class="flex_row mt-10">
					<div class="form_label">负责人</div>
					<personselect :disabled="workStatus ==30" :issingle="isSingle" ref="personselect_respon" style="width:55vw;"></personselect>
				</div>
				<div class="flex_row mt-10">
					<div class="form_label">试验时间</div>
					<div>{{deviceSwitch.switchDate || nowDate}}</div>
				</div>
				<div class="flex-row mt-10">
					<div class="form_label">设备单元名称</div>
					<input class="switch-ipt" :value="deviceSwitch.deviceName" v-model="deviceSwitch.deviceName" maxlength="60"
					 :disabled="workStatus ==30" />
				</div>
				<div class="flex-row mt-10">
					<div class="form_label">试验切换人员</div>
					<div>{{'[' + deviceSwitch.switchStaffCode + ']' + deviceSwitch.switchStaffName}}</div>
				</div>

				<hr size="1" style="color: #999;border-style: dashed; widows: 250px;" />

				<div class="flex-between mt-10">
					<div>试验内容</div>
					<div @tap="addCheckItem" class="communication-add-btn">
						+
					</div>
				</div>
				<div class="mt-10">
					<div class="flex-between mt-10" v-for="(item,index) in checkItemNoteList" :key="index">
						<div class="check-content">
							<!-- <span>{{index}}</span> -->
							<input style="width: 40vw;" :disabled="item.orgCode=='A00'||workStatus ==30" v-model="item.checkItemContent" />
						</div>
						<div class="flex-row">
							<div v-for="(item1,index1) in checklist" :key="index" class="flex-row">
								{{item1.itemText}}
								<input @click="chooseRadio(index)" style="width: 18px;margin-right: 5px;" v-model="item.checkItemResult" type="radio"
								 :value="item1.itemValue" :disabled="workStatus ==30 " id="">
							</div>
							<span @tap="deleteCheckItem(index)" v-show="item.orgCode==user.stationNewCode && workStatus <30"
							class="communication-del-btn">删除</span>
						</div>
					</div>
					<hr size="1" class="hr-line" />
				</div>

				<div style="margin: 5px 0;">切换试验结论</div>
				<textarea name="" id="" maxlength="600" :disabled="status>30" v-model="deviceSwitch.switchRemark">
					</textarea>
				<hr size="1" style="color: #999;border-style: dashed; widows: 250px;" />
				
				<div class="list-head">
					<div>附件</div>
					<button class="submit_btn" @tap="upload" v-if="!(workStatus>20)">上传</button>
					<hr size="1" class="hr-line" />
					<div v-if="fileIds.length>0">
						<div style="margin-bottom: 1vh;" v-for="(item,index) in filesList" class="flex-row">
							<div v-if="filesList.length>0" style="width: 100vw;" class="flex-between">
								<div class="ip-text">
									{{item.fileName}}
								</div>
								<div class="flex-row">
									<button v-if="!(workStatus>20)" style="background: red;color: white;border: 0;width: 10vw;" class="cancel_btn" @tap="delDown(item)">删除</button>
									<button style="width: 10vw;" class="submit_btn" @tap="downLoad(item)">下载</button>
								</div>
							</div>
	
						</div>
					</div>
					<div v-else style="text-align: center;">
						暂无数据
					</div>
				</div>
					<hr size="1" style="color: #999;border-style: dashed; widows: 250px;" />
					

				<div class="flex-between list-head">
					<div class="flex-row" style="font-weight: bold;">
						<div class="icon"></div>
						流程日志
					</div>
				</div>
				<processlog :processlogid='workId'></processlog>
			</div>
			<div class="popup-bg" v-if="submitDia">
				<div style="padding: 15px 15px 0px" class="add-box" @click@tap.stop="clickStop">
					<div style="height: 5vh;" class="flex-row m-10">
						<div style="width: 70vw;font-size: 17px;">隐患描述
						</div>
					</div>
					<div style="max-height: 30vw;overflow: auto;">
						<div v-for="item in questiontArr">
							切换试验{{item.name}}
						</div>
						<div style="text-align: center;" v-if="questiontArr.length==0">
							暂无数据
						</div>
					</div>
					<hr size="1" style="color: #999;border-style: dashed; widows: 250px;" />
					<div style="height: 5vh;" class="flex-row m-10">
						<div style="width: 70vw;font-size: 17px;">选择切换结果确认人
						</div>
					</div>
					<div class="flex-row">
						<div style="margin-right: 5px">切换结果确认人</div>
						<personselect ref="personselect_switch" style="width:50vw;"></personselect>
					</div>
					<div class="pop-bottom">
						<div @tap="submit('submit')">提交</div>
						<div class="color-red" @tap="submitDia = false">取消</div>
					</div>
				</div>
			</div>
			<div class="popup-bg" v-if="backOrApprove">
				<div style="padding: 15px 15px 0px" class="add-box" @click@tap.stop="clickStop">
					<div style="height: 5vh;" class="flex-row m-10">
						<div style="width: 70vw;font-size: 17px;">隐患描述
						</div>
					</div>
					<div style="max-height: 30vw;overflow: auto;">
						<div v-for="item in questiontArr">
							切换试验{{item.name}}
						</div>
						<div style="text-align: center;" v-if="questiontArr.length==0">
							暂无数据
						</div>
					</div>
					<hr size="1" style="color: #999;border-style: dashed; widows: 250px;" />
					<div style="height: 5vh;" class="flex-row m-10">
						<div style="width: 70vw;font-size: 17px;">意见描述
						</div>
					</div>
					<div class="mt-10" v-if="status > 30">
						<div>意见描述</div>
						<textarea maxlength="255" placeholder="请输入审批意见" v-model="advance" class="mt-10"></textarea>
					</div>
					<div class="pop-bottom">
						<div v-if="isBack" @tap="sendBack">退回</div>
						<div v-if="!isBack" @tap="submit('submit','approve')">通过</div>
						<div class="color-red" @tap="backOrApprove = false;advance='';">取消</div>
					</div>
				</div>
			</div>
			<div style="width: 100%;height: 60px;"></div>
			<div class="fixed-bottom flex-between">
				<button class="cancel_btn" v-if="isShowHandle()" @click="initApprove('back')">退回</button>
				<button class="submit_btn" v-if="isShowHandle()" @click="initApprove('approve')">通过</button>
				<button class="submit_btn" v-if="isShowEdit()" @click="submit('save')">保存</button>
				<button class="submit_btn" v-if="isShowEdit()" @click="initDefectInfo">提交</button>
				<button @tap="goBack" class="cancel_btn">返回</button>
			</div>
		</div>
		</div>

		<!-- <div class="popup-bg" v-if="showSubmit" @click="showSubmit = false">
				<div class="add-box"  @click.stop="clickStop">
					<div class="flex-row user-form">
						<div class="pop-label">值班人</div>
						<input class="pop-ipt" />
					</div>
					<div class="pop-bottom">
						<div class="color-blue">提交</div>
						<div class="color-red" @click="showSubmit = false">取消</div>
					</div>
				</div> 
			</div> -->
		</div>


		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/vue.js"></script>
		<script type="text/javascript" src="../../../../js/jquery-3.2.1.min.js"></script>
		<script src="../../static/components/personSelect.js"></script>
		<script src="../../static/js/neiosCommon.js"></script>
		<!--公共js页面必需-->
		<script type="text/javascript" src="../../static/js/neiosRequst.js"></script>
		<script src="../../static/components/processLog.js"></script>
		<script src="../../static/js/upLoadHelper.js"></script>
		<!--流程日志-->
		<script type="text/javascript" charset="utf-8">
			document.addEventListener('focusout', function(e) {
				var classList = document.body.classList
				if (classList.contains('mui-focusin')) {
					classList.remove('mui-focusin')
				}
			})
			projectVM = new Vue({
				el: "#content",
				components: {
					personselect,
					processlog
				},
				data: {
					filesList:[],
					fileIds:'',
					isBack: false,
					backOrApprove: false,
					isSingle: true,
					user: '',
					result: '',
					workStatus: '',
					workId: '',
					advance: '',
					status: '',
					nowDate: '',
					checklist: [],
					status: '',
					questiontArr: [],
					delCheckItems: [],
					show_popup: false,
					list: [],
					checkItemNoteList: [],
					deviceSwitch: '',
					submitDia: false,
					checkItem: {
						checkResultTypeList: [],
						checkItemNoteId: '', //检查项记录主键
						busiInfoId: '', //业务明细主键,检查项记录对应的业务明细记录的主键
						configDetailedId: '', //检查项主键
						checkItemConfigId: '',
						orgCode: '', //机构编号
						checkItemContent: '', //检查项内容
						workType: '',
						checkItemRequirement: '', //检查项要求
						checkItemResult: '', //检查结果
						createBy: '',
						createStaffName: '',
						itemSolveStaffCode: '', //检查消除人编号
						itemSolveStaffName: '',
						problemLog: '', //发现问题记录
						modifyBy: '',
						modifyStaffName: '', //检查消除人姓名
						headquartersDetailedId: '', //总部检查项主键,分公司修改总部检查项时记录总部检查项主键
						parentDetailedId: '' //分组父级检查项主键,安全设施检查记录使用

					},
				},
				created() {
					console.log(localStorage.getItem('todoWork'))
					this.workId = JSON.parse(localStorage.getItem('todoWork')).obj.workId
					this.workStatus = JSON.parse(localStorage.getItem('todoWork')).obj.workStatus
					this.user = JSON.parse(localStorage.getItem('neiosUser'))
					console.log(this.user, '===')
				},
				mounted: function() {
					this.getDictcode()
					this.getDetail()
					this.getNowdate()
				},
				methods: {
									// 上傳
		upload() {
			let that = this
			mui.neiosCommon.doUploads(function(ret) {
				if ("0" == ret.code) {
					console.log("成功：" + JSON.stringify(ret))
					// mui.toast('文件'+ret.data.fileName+"上传成功");
					that.fileIds == "" ? that.fileIds += ret.data.fileId : that.fileIds += "," + ret.data.fileId;
					that.getFileds()
				} else {
					mui.toast('文件上传失败');
				}
			}, function(err) {
				mui.toast('文件上传失败');
			})
		},
		// 删除文件
		delDown(data){
			let myFileIds = this.fileIds.split(',')
			myFileIds.splice(myFileIds.findIndex(item => item==data.fileId),1)
			this.fileIds = myFileIds.join(',')
			console.log(this.fileIds)
			this.getFileds()
		},
		// 获取文件列表
		getFileds(){
			mui.neiosRequst.httpRequst('/app/common/getFileList', {fileIds:this.fileIds},
				(data) => {
					if (data.code == '0') {
						console.log(JSON.stringify(data.data))
						this.filesList = data.data
					} else {
						mui.toast("获取失败：" + data.msg);
					}
				},
				(data) => {
					mui.toast("退回失败：" + data.msg);
				}
			);
		},
		// 下载
		downLoad(data) {
			let url = "/app/common/downloadFile";
			let param = {};
			param.fileId = data.fileId;
			mui.neiosCommon.downLoadFile(param, function(ret) {
				mui.plusReady(function() {
					plus.nativeUI.closeWaiting();
				})
				//调用存储
				var callbackID = plus.bridge.callbackId(function(ret) {
					mui.toast(ret[0])
				}, function(err) {
					mui.toast('文件下载失败')
				});
				plus.bridge.execSync("FileHelper", "doFileSave", [callbackID, ret, data.fileName, "Argus3", "Argus4"])
			}, function(err) {
				mui.plusReady(function() {
					plus.nativeUI.closeWaiting();
				})
				mui.toast('文件下载失败')
			});
		},
					//判断是否显示办理
					isShowHandle() {
						if (this.workStatus == '30') {
							return true
						} else {
							return false
						}
					},
					//判断是否显示编辑
					isShowEdit() {
						if (this.workStatus == '20') {
							return true
						} else {
							return false
						}
					},
					addCheckItem() {
						if (this.workStatus != 30) {
							this.checkItem.orgCode = this.user["stationNewCode"];
							this.checkItem.createBy = this.user["userId"];
							this.checkItem.createStaffName = this.user["name"];
							this.checkItem.modifyBy = this.user["userId"];
							this.checkItem.modifyStaffName = this.user["name"];
							this.checkItem.checkItemResult = [];
							this.checkItem.workType = '0106';
							this.checkItem.busiInfoId = this.deviceSwitch.deviceSwitchId;
							let checkItem = JSON.parse(JSON.stringify(this.checkItem))
							this.checkItemNoteList.push(checkItem);
						}

					},
					//返回上一页
					goBack() {
						let page2 = plus.webview.getWebviewById("../sitOperation/terminalwork/terminalwork.html");
						let param = {}
						param.isRefresh = true
						mui.fire(page2, 'isRefresh', param);
						mui.back()
					},
					//保存提交
					submit(e, f) {
						var that = this
						if (e == 'submit' && !f) {
							if (that.$refs.personselect_approve.personids == '') {
								mui.toast('请输入批准人')
								return
							} 
						}
						if(this.submitDia && this.$refs.personselect_switch && !this.$refs.personselect_switch.personids){
							mui.toast('请选择切换结果确认人');
							return;
						}
						this.deviceSwitch.approveStaffCode = that.$refs.personselect_approve.personids
						this.deviceSwitch.approveStaffName = that.$refs.personselect_approve.person.split(']')[1]
						this.deviceSwitch.approveStaff = that.$refs.personselect_approve.person
						this.deviceSwitch.responsibleStaffCode = that.$refs.personselect_respon.personids
						this.deviceSwitch.responsibleStaffName = that.$refs.personselect_respon.person.split(']')[1]
						this.deviceSwitch.dataSource = 'NEIOS_APP'+localStorage.getItem("currVersion")
						let nodeDealStaffCode = this.$refs.personselect_switch ? this.$refs.personselect_switch.personids : ''
						let nodeDealStaffName = this.$refs.personselect_switch ? this.getName(this.$refs.personselect_switch.person) :
							''
						var param = {
							delCheckItems: this.delCheckItems,
							operate: e,
							companyCode: this.user.companyCode,
							stationCode: this.user.stationCode,
							workType: '0106',
							nodeDealStaffCode: this.status > 30 ? that.deviceSwitch.switchStaffCode : nodeDealStaffCode,
							nodeDealStaffName: this.status > 30 ? that.deviceSwitch.switchStaffName : nodeDealStaffName,
							approveDesc: this.advance,
							workId: this.workId,
							userId: this.user.userId,
							name: this.user.name,
							deviceSwitch: this.deviceSwitch,
							questionArr: this.questiontArr,
							nodeCreateStaffCode: this.user["userId"],
							nodeCreateStaffName: this.user["name"]

						}
						param.deviceSwitch.checItemskList = this.checkItemNoteList
						var list = JSON.parse(JSON.stringify(this.checkItemNoteList))
						var unable = false
						list.forEach(item => {
							if (item.checkItemResult == 1) {
								item.checkItemResult = ['是']
							} else if (item.checkItemResult == 2) {
								item.checkItemResult = ['否']
							} else if (item.checkItemResult == 3) {
								item.checkItemResult = ['告警']
							} else {
								unable = true
							}
						})
						if (e == 'submit' && unable) {
							mui.toast('请选择试验结果')
							return
						}
						param.deviceSwitch.checkItems = list
						param.fileIds = this.fileIds
						console.log(JSON.stringify(param))
						mui.neiosRequst.httpRequst('/app/regularWork/deviceSwitch/saveDeviceSwitch', param,
							(data)=> {
								mui.toast('操作成功')
								setTimeout(function() {
									if (e != 'save') {
										that.goBack()
									} else {
										window.location.reload()
									}
								}, 1000);
							},
							function(data) {

							})
					},
					//删除
					deleteCheckItem(index) {
						if (this.checkItemNoteList[index].checkItemNoteId == null || this.checkItemNoteList[index].checkItemNoteId ==
							'') {
							this.checkItemNoteList.splice(index, 1);
						} else {
							this.delCheckItems.push(this.checkItemNoteList[index]);
							this.checkItemNoteList.splice(index, 1);
						}
					},
					getName(data) {
						console.log(data)
						if (data) {
							let list = []
							data.split(',').map((v) => {
								list.push(v.split(']')[1])
							})
							return list.join(',');
						} else {
							return data
						}

					},
					//切换结论
					changeswitchRemark() {
						var arr = this.checkItemNoteList
						this.questiontArr = []
						var questiontRxt = []
						var that = this
						arr.forEach(item => {
							if (item.checkItemResult > 1) {
								var txt = item.checkItemResult == 2 ? '不合格' : '告警'
								questiontRxt.push(item.checkItemContent + '。' + txt + '。')
								that.questiontArr.push({
									name: item.checkItemContent + '。' + txt,
									reson: ''
								})
							}
						});
						console.log(JSON.stringify(that.questiontArr))
						this.$nextTick(() => {
							that.deviceSwitch.switchRemark = '切换试验结论：' + questiontRxt.join('')
							if (that.questiontArr.length == 0) {
								that.deviceSwitch.switchRemark = ''
							}
						})
					},
					initApprove(type) {
						if (type == 'back') {
							this.isBack = true
						} else {
							this.isBack = false
						}
						this.backOrApprove = true
						var arr = this.checkItemNoteList
						this.questiontArr = []
						var questiontRxt = []
						var that = this
						arr.forEach(item => {
							if (item.checkItemResult > 1) {
								var txt = item.checkItemResult == 2 ? '不合格' : '告警'
								questiontRxt.push(item.checkItemContent + '。' + txt + '。')
								that.questiontArr.push({
									name: item.checkItemContent + '。' + txt,
									reson: ''
								})
							}
						});
					},
					//提交展示缺陷
					initDefectInfo() {
						var list = JSON.parse(JSON.stringify(this.checkItemNoteList))
						var unable = false
						let contentUnable = false
						list.forEach(item => {
							console.log(item.checkItemResult)
							if (item.checkItemContent == '') {
								contentUnable = true
							}
							if (item.checkItemResult == 1) {
								item.checkItemResult = ['是']
							} else if (item.checkItemResult == 2) {
								item.checkItemResult = ['否']
							} else if (item.checkItemResult == 3) {
								item.checkItemResult = ['告警']
							} else {
								unable = true
							}
						})
						if (contentUnable) {
							mui.toast('请输入切换试验内容')
							return
						}
						if(!this.deviceSwitch.switchRemark){
							mui.toast('请输入切换试验结论')
							return
						}
						if (this.$refs.personselect_approve.personids == '') {
							mui.toast('请输入批准人')
							return
						} else if (this.$refs.personselect_respon.personids == '') {
							mui.toast('请输入负责人')
							return
						}

						if (unable) {
							mui.toast('请选择试验结果')
							return
						}
						this.submitDia = true
						var arr = this.checkItemNoteList
						this.questiontArr = []
						var questiontRxt = []
						var that = this
						arr.forEach(item => {
							if (item.checkItemResult > 1) {
								var txt = item.checkItemResult == 2 ? '不合格' : '告警'
								questiontRxt.push(item.checkItemContent + '。' + txt + '。')
								that.questiontArr.push({
									name: item.checkItemContent + '。' + txt,
									reson: ''
								})
							}
						});
					},
					//选择单选框
					chooseRadio(e) {
						var that = this
						this.$nextTick(() => {
							that.changeswitchRemark()
							// var btnArray = ['否', '是'];
							// mui.confirm('切换试验结论发生变化是否需要覆盖?', '提示', btnArray, function(e) {
							// if(e.index == 1) {

							// } 
							// else{

							// }
							// })

						})

					},
					//获取当前时间
					getNowdate() {
						var date = new Date()
						var year = date.getFullYear()
						var month = date.getMonth()
						var day = date.getDate()
						month = month*1 + 1
						if (month.toString().length < 2) {
							month = '0' + month
						}
						if (day.toString().length < 2) {
							day = '0' + day
						}
						this.nowDate = year + '-' + month + '-' + day
					},
					//流程退回
					sendBack() {
						if (this.advance == '') {
							mui.toast('请输入意见描述')
							return
						}
						var that = this
						var param = {
							"workId": this.workId,
							"workType": "0106",
							"nodeDealStaffCode": this.user.userId,
							"nodeDealStaffName": this.user.name,
							"approveDesc": this.advance,
							"nodeDealStaffRole": '0',
							"forwardNode": '1',
							"nodeVisibleRange": '20',
						}
						mui.neiosRequst.httpRequst('/app/personWork/sendBack', param,
							(data)=> {
								mui.toast('操作成功')
								this.goBack()
							},
							function(data) {

							})
					},
					//获取工作详情
					getDetail() {
						var that = this
						var param = {
							companyCode: this.user.companyCode,
							deviceSwitchId: "",
							name: this.user.name,
							stationCode: this.user.stationCode,
							userId: this.user.userId,
							workId: this.workId,
							workType: "0106",
						}
						mui.neiosRequst.httpRequst('/app/regularWork/deviceSwitch/getCheckItems', param,
							function(data) {
								console.log(JSON.stringify(data.data.data.deviceSwitch))
								that.deviceSwitch = data.data.data.deviceSwitch
								that.checkItemNoteList = data.data.data.checkItemNoteList
								that.fileIds = data.data.data.attachIds;
								that.getFileds()
								that.status = data.data.data.deviceSwitch.status
								if (!that.deviceSwitch.deviceName) {
									that.deviceSwitch.deviceName = '直流系统'
								}
								if (!that.deviceSwitch.switchStaffCode) {
									that.deviceSwitch.switchStaffCode = that.user.userId
									that.deviceSwitch.switchStaffName = that.user.name
								}
								if (that.deviceSwitch.approveStaffName == null) {
									that.$refs.personselect_approve.person = ''
									that.$refs.personselect_approve.personids = ''
								} else {
									that.$refs.personselect_approve.person = '[' + that.deviceSwitch.approveStaffCode + ']' + that.deviceSwitch
										.approveStaffName
									that.$refs.personselect_approve.personids = that.deviceSwitch.approveStaffCode
								}

								if (that.deviceSwitch.responsibleStaffName == null) {
									that.$refs.personselect_respon.person = ''
									that.$refs.personselect_respon.personids = ''
								} else {
									that.$refs.personselect_respon.person = '[' + that.deviceSwitch.responsibleStaffCode + ']' + that.deviceSwitch
										.responsibleStaffName
									that.$refs.personselect_respon.personids = that.deviceSwitch.responsibleStaffCode
								}
							},
							function(data) {

							})
					},
					//获取检查参数
					getDictcode() {
						var that = this
						var param = {
							dictCode: "CHECK_RESULT_TYPE"
						}
						mui.neiosRequst.httpRequst('/app/common/getItemsByDictCodes', param,
							function(data) {
								that.checklist = data.data.CHECK_RESULT_TYPE

							},
							function(data) {

							})
					},


				},

			})
		</script>
	</body>

</html>
